//
//  WYAdvertisementCell.m
//  Boss
//
//  Created by admin on 2018/6/8.
//  Copyright © 2018年 admin. All rights reserved.
//

#import "WYAdvertisementCell.h"
@interface WYAdvertisementCell()


@property (strong, nonatomic) IBOutlet UILabel *titleLabel;
@property (strong, nonatomic) IBOutlet UILabel *deseLabel;

@property(nonatomic ,strong) UIButton           *playBtn;
@property (strong, nonatomic) IBOutlet UILabel *pageLabel;

@end
@implementation WYAdvertisementCell

- (void)awakeFromNib {
    [super awakeFromNib];
    self.adImageView.tag = 101;
    
    self.playBtn = [UIButton buttonWithType:UIButtonTypeCustom];
    [self.playBtn setImage:[UIImage imageNamed:@"icon_play"] forState:UIControlStateNormal];
    [self.playBtn addTarget:self action:@selector(playAction:) forControlEvents:UIControlEventTouchUpInside];
    [self.adImageView addSubview:self.playBtn];
    [self.playBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.center.equalTo(self.adImageView);
        make.width.height.mas_equalTo(50);
    }];
    
    
   // self.playBuuton.hidden = YES;
   // Initialization code
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}
-(void)setAdvertisementMessage:(WYAdvertisementMessage *)advertisementMessage
{
    _advertisementMessage = advertisementMessage;
    if (advertisementMessage.type.intValue==1) {
        [self.adImageView sd_setImageWithURL:[NSURL URLWithString:[NSString stringWithFormat:@"%@!default",advertisementMessage.adPic]] placeholderImage:[UIImage imageNamed:@"占位图"]];
        self.titleLabel.text=advertisementMessage.title;
        self.deseLabel.text = advertisementMessage.businessName;
        self.playBtn.userInteractionEnabled = NO;
         self.playBtn.hidden = YES;
        
        WEAKSELF;
        UITapGestureRecognizer *ges = [[UITapGestureRecognizer alloc]initWithActionBlock:^(id  _Nonnull sender) {
            if ([weakSelf.delegate respondsToSelector:@selector(clickImageViewWithUrl:WithLinkType:WithLinkName:)]) {
                [weakSelf.delegate clickImageViewWithUrl:advertisementMessage.web WithLinkType:advertisementMessage.linkType WithLinkName:advertisementMessage.businessName];
            }
            
            
        }];
        [self.adImageView addGestureRecognizer:ges];
        
        
    }
    
    if (advertisementMessage.type.intValue==2) {
        [self.adImageView sd_setImageWithURL:[NSURL URLWithString:advertisementMessage.videoPic] placeholderImage:nil];
        self.titleLabel.text=advertisementMessage.title;
        self.deseLabel.text =advertisementMessage.businessName;
       self.playBtn.userInteractionEnabled = YES;
        self.playBtn.hidden = NO;
       // [self playAction:nil];
    }
    self.pageLabel.text = [NSString stringWithFormat:@"%@阅读量",self.advertisementMessage.pageView];
    if (advertisementMessage.type.intValue==3) {
        [self.adImageView sd_setImageWithURL:[NSURL URLWithString:[NSString stringWithFormat:@"%@!default",advertisementMessage.adPic]] placeholderImage:nil];
        self.titleLabel.text=advertisementMessage.title;
        self.deseLabel.text =advertisementMessage.web;
        self.playBtn.userInteractionEnabled = NO;
        self.playBtn.hidden = YES;
    }
}


- (void)playAction:(UIButton *)sender {
    
//    UIButton *btn = (UIButton *)sender;
//    btn.selected = !btn.isSelected;
//    btn.hidden = btn.selected;
    
    
    
    if ([self.delegate respondsToSelector:@selector(clickPlayButtonWithCell:)]) {
        [self.delegate clickPlayButtonWithCell:self];
    }
    
    
    
    
}








@end
